<template>
  <div class="active-area-box">
    <div class="select1">
      <AreaSelect></AreaSelect>
    </div>
    <ActiveTime></ActiveTime>
    <TabDatas></TabDatas>
    <DetailsDialog></DetailsDialog>
  </div>
</template>

<script>
import { Bus } from "../../Bus";
import { getareaactivity, queryareaactivity } from "../../api/datas";
import AreaSelect from "../../components/sales/areaSelect";
import ActiveTime from "../../components/active/activeTime";
import TabDatas from "../../components/sales/TabDatas";
import DetailsDialog from "../../components/sales/DetailsDialog";
export default {
  components: {
    ActiveTime,
    TabDatas,
    AreaSelect,
    DetailsDialog,
  },
  data() {
    return {
      isShow: true,
      areaArr: {
        province: "",
        city: "",
        area: "",
      },
      lists: [
        {
          name: "省",
          prop: "province",
        },
        {
          name: "市",
          prop: "city",
        },
        {
          name: "区",
          prop: "area",
        },
        {
          name: "总活跃度",
          prop: "active_value",
        },
      ],
      areaActives: [],
      istabpane: false,
    };
  },
  mounted() {
    Bus.$on("areadatas", (value) => {
      this.areaArr.province = value.province;
      this.areaArr.city = value.city;
      this.areaArr.area = value.area;
    });
    Bus.$emit("isshowcity", this.isShow);
    Bus.$emit("isshowarea", this.isShow);
    Bus.$emit("tab-lists", this.lists);
    Bus.$emit("istabpane", this.istabpane);
    this.activedatas();
  },
  methods: {
    //获取所有区活跃度
    activedatas() {
      getareaactivity({}).then((res) => {
        this.areaActives = res.resoult;
        if (this.areaArr.province != "" && this.areaArr.province != "全部省") {
          this.areaActives = this.areaActives.filter((item) => {
            if (this.areaArr.province == item.province) {
              return item;
            }
          });
          if (this.areaArr.city != "" && this.areaArr.city != "全部市") {
            this.areaActives = this.areaActives.filter((item) => {
              if (this.areaArr.city == item.city) {
                return item;
              }
            });
            if (this.areaArr.area != "" && this.areaArr.area != "全部区") {
              this.areaActives = this.areaActives.filter((item) => {
                if (this.areaArr.area == item.area) {
                  return item;
                }
              });
            }
          }
        } else {
          this.areaActives = res.resoult;
        }
        Bus.$emit("tab-datas", this.areaActives);
      });
    },
  },
  watch: {
    areaArr: {
      deep: true,
      handler() {
        this.activedatas();
      },
    },
  },
};
</script>

<style lang="less" scoped>
.active-area-box {
  padding-top: 30px;
}
.active-time {
  margin: 30px 0px 0px 30px;
}
.select1 {
  margin-left: 30px;
  margin-right: 50px;
  width: 400px;
}
</style>